package org.teamh.connection.handler;

import org.teamh.game.Start;
import org.teamh.game.StartGame;

public class ExceptionHandler extends MasterHandler {

	public ExceptionHandler(Start start) {
		super(start);
	}

	public boolean handleMsg(String line) {
		if (line.startsWith("ERROR:")) {
			if (line.contains("WRONG PARAMETER")) {
				if(StartGame.PRINT_MESSAGES) {
					System.out.println("wrong parameter, watch syntax!");		
				}
				if (start.getGui().getNifty() != null && start.getGui().getNifty().getCurrentScreen().getScreenId().contains("loading")) {
					start.getGui().setFollowingScreen(start.getGui().getLobbyScreen());
					start.getGui().getLobbyScreen().getLobbyController().setErrorOccured(true);
				}
				return true;
			} else {
				if(StartGame.PRINT_MESSAGES) {
					System.out.println("Unknwon Error: " + line);
				}
				return true;
			}
		} else if (line.startsWith("SE1")) {
			return true;
		} else if (line.startsWith("OK")) {
			return true;
		} else if (line.startsWith("TEAM")) {
			return true;
		} else if (line.startsWith("EOT")) {
			if(start.getConnection().getMessageReceiver() instanceof ConnectionHandler) {
				((ConnectionHandler)start.getConnection().getMessageReceiver()).setEot(true);
			}
			return true;
		} else {
			return false;
		}
	}
	
}
